package com.estar.assistsurvy.adapter;

import android.support.annotation.IdRes;
import android.support.v7.widget.RecyclerView;
import android.util.SparseArray;
import android.view.View;
import android.widget.TextView;

/**
 * Created by admin on 2016/9/21.
 */

public  class BaseViewHolder extends RecyclerView.ViewHolder {

    private SparseArray<View> viewHolder;

    public interface OnItemClickListener{
        public void OnItemClickListener(int position);
    }

    public BaseViewHolder(View view) {
        super(view);
        viewHolder = new SparseArray<View>();
    }

    public void setOnItemClickListener(final OnItemClickListener onItemClickListener,final int posion){
       if(onItemClickListener!=null){
           itemView.setOnClickListener(new View.OnClickListener() {
               @Override
               public void onClick(View v) {
                   onItemClickListener.OnItemClickListener(posion);
               }
           });

       }
    }
    @SuppressWarnings("unchecked")
	protected <T extends View> T getView(@IdRes int viewId) {
        View childView = viewHolder.get(viewId);
        if (childView == null) {
            childView = (T)itemView.findViewById(viewId);
            viewHolder.put(viewId, childView);
        }
        return (T) childView;
    }
    /**
     *
     * @param id
     * @return
     */
    public TextView getTextView(int id) {

        return getView(id);
    }
}
